package com.example.shopping.controller;

import com.example.shopping.pojo.User;
import com.example.shopping.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/*
Create by 苍狼 于 2020/1/16
站在巅峰看世界，
落在深渊思人生。
*/
//@CrossOrigin
@Controller
//@Api("登录")
public class UserController {

    @Autowired
    private UserService userService;


    //登录入口
    @RequestMapping("/login")
    public String login1() {
        System.out.println(111111111);
        return "login";
    }

    @RequestMapping("/loginTo")
    @ApiOperation(value = "登录方法")
    public String loginTo(String uname, String upwd, HttpServletRequest request) {
        System.out.println("2222222222");
        User user = userService.login(uname, upwd);
        if (user != null) {
            request.getSession().setAttribute("user",user);
            //登录首页
            return "index";
        }
        return "redirect:login";
    }

}
